import { Effect, Reducer, Subscription } from "umi";

export interface SecurityModelState {
  name: string;
  needLogin: boolean;
}

export interface SecurityModelType {
  namespace: 'security';
  state: SecurityModelState;
  effects: {
    // 获取用户信息
    queryInfo: Effect;
    // 登录
    login: Effect;
    // 注册
    register: Effect;
    // 忘记密码
    forgetPwd: Effect;
  };
  reducers: {
    save: Reducer<SecurityModelState>;
  },
  subscriptions: { setup: Subscription };
}

const SecurityModel: SecurityModelType = {
  namespace: 'security',
  state: {
    name: '安全层',
    needLogin: false,
  },
  effects: {
    *queryInfo({ payload }, { call, put }) { },
    *login({ payload }, { call, put }) { },
    *register({ payload }, { call, put }) { },
    *forgetPwd({ payload }, { call, put }) { },
  },
  reducers: {
    save(state, action) {
      return {
        ...state,
        ...action.payload
      };
    }
  },
  subscriptions: {
    setup({ dispatch, history }) {
      return history.listen(({ pathname }) => { })
    }
  }
}

export default SecurityModel;